<?php
/**
 * Created by PhpStorm.
 * User: sunzexin
 * Date: 2018/1/28
 * Time: 11:00
 */

namespace App\Http\Controllers\MiniProgram;


use App\Http\Logics\MiniProgram\WechatArticleLogic;
use App\Http\Traits\WechatArticleTrait;
use App\Http\Controllers\BaseController;
class WechatArticleController extends BaseController
{
    use WechatArticleTrait;
    public function pushArticle()
    {
        $password = "yiicca";
        if (empty($_POST['__sign'])
            || md5("{$password}shenjianshou.cn") != trim($_POST['__sign'])) {
            echo json_encode([
                "result" => 2,
                "reason" => "发布失败, 错误原因: 发布密码验证失败!"
            ]);
            exit;
        }
        $article_title = $this->article_title;
        $article_author = $this->article_author;
        $weixin_name = $this->weixin_name;
        $weixin_nickname = $this->weixin_nickname;
        $article_publish_time = $this->article_publish_time;
        $article_thumbnail = $this->article_thumbnail;
        $article_brief = $this->article_brief;
        $article_content = $this->article_content;
        $is_original = $this->is_original;
        $weixin_avatar = $this->weixin_avatar;
        $weixin_introduce = $this->weixin_introduce;
        $weixin_qr_code = $this->weixin_qr_code;
        $article_images = $this->article_images;
        $idx = $this->idx;
        $data = [
            'article_title' => $article_title,
            'article_author' => $article_author,
            'weixin_name' => $weixin_name,
            'weixin_nickname' => $weixin_nickname,
            'article_publish_time' => $article_publish_time,
            'article_thumbnail' => $article_thumbnail,
            'article_brief' => $article_brief,
            'article_content' => $article_content,
            'is_original' => $is_original,
            'weixin_avatar' => $weixin_avatar,
            'weixin_introduce' => $weixin_introduce,
            'weixin_qr_code' => $weixin_qr_code,
            'article_images' => $article_images,
            'idx' => $idx
        ];
        $response = WechatArticleLogic::pushArticle($data);
        if ($response->code){
            echo json_encode([
                'result' => $response->code,
                'reason' => $response->message
            ]);
        }
        echo json_encode(["result" => 1, "data" => "发布成功"]);
        exit;
    }

    public function getWechatArticleList()
    {
        $limit = $this->limit;
        $data = [];
        WechatArticleLogic::getWechatArticleList($data);
    }
}